package com.learn.demo.controller;

import com.learn.demo.service.DeadLetterMsgProvider;
import com.learn.demo.service.MessageProvider;
import com.learn.demo.service.MessageSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class SendMessageController {
    @Autowired
    private MessageProvider messageProvider;
    @Autowired
    private MessageSender messageSender;
    @Resource
    private DeadLetterMsgProvider deadLetterMsgProvider;

    @GetMapping("/sendMessage")
    public String sendMessage(){
        return messageProvider.send();
    }

    @GetMapping("/sendDelayMessage/{message}")
    public String sendDelayMessage(@PathVariable(name = "message") String message) {
        messageSender.sendLazy(message);
        return "Ok";
    }

    @GetMapping("/sendDeadLetterMessage")
    public String sendDeadLetterMessage(){
        return deadLetterMsgProvider.send();
    }
}
